package com.swjd.jingle.fragment;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.swjd.jingle.R;
import com.swjd.jingle.pojo.User;
import com.xuexiang.xui.widget.imageview.RadiusImageView;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;

public class MyFragment extends BaseFragment implements View.OnClickListener {


    @BindView(R.id.img_scan)
    ImageView imgScan;
    @BindView(R.id.img_set)
    ImageView imgSet;
    @BindView(R.id.img_head_portrait)
    RadiusImageView imgHeadPortrait;
    @BindView(R.id.tv_nickname)
    TextView tvNickname;
    @BindView(R.id.tv_signature)
    TextView tvSignature;
    @BindView(R.id.tv_attention)
    TextView tvAttention;
    @BindView(R.id.tv_fans)
    TextView tvFans;
    @BindView(R.id.img_qrcode)
    ImageView imgQrcode;
    @BindView(R.id.tv_sold)
    TextView tvSold;
    @BindView(R.id.layout_sold)
    LinearLayout layoutSold;
    @BindView(R.id.tv_buy)
    TextView tvBuy;
    @BindView(R.id.layout_buy)
    LinearLayout layoutBuy;
    @BindView(R.id.tv_collected)
    TextView tvCollected;
    @BindView(R.id.layout_collected)
    LinearLayout layoutCollected;
    @BindView(R.id.lv_released)
    ListView lvReleased;
    @BindView(R.id.tv_none_hint)
    TextView tvNoneHint;
    private Animation setAnim1, setAnim2;

    @Override
    public void initialize() {
        User user = app.getUserInfo();
        tvNickname.setText(user.getName());
        tvSignature.setText(user.getIntro());
        tvAttention.setText("关注 " + user.getConcerns().size());
        tvFans.setText("粉丝 " + user.getFans().size());
    }

    @Override
    public void initViews() {

    }


    @Override
    public void initData() {
        setAnim1 = AnimationUtils.loadAnimation(getContext(), R.anim.anim_set1);
        setAnim2 = AnimationUtils.loadAnimation(getContext(), R.anim.anim_set2);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_my;
    }

    @Override
    public void onResume() {
        super.onResume();
        imgSet.startAnimation(setAnim2);
    }

    @Override
    @OnClick({R.id.img_scan, R.id.img_set, R.id.img_head_portrait, R.id.tv_nickname, R.id.tv_signature, R.id.tv_attention, R.id.tv_fans, R.id.img_qrcode, R.id.layout_sold, R.id.layout_buy, R.id.layout_collected})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_scan:
                getRuntimePermission();
                break;
            case R.id.img_set:
                imgSet.startAnimation(setAnim1);
                new Timer().schedule(new TimerTask() {
                    @Override
                    public void run() {
                        fragmentManager.beginTransaction().replace(R.id.layout_main, new SetFragment())
                                .addToBackStack(null)
                                .commit();
                    }
                }, 300);
                break;
            case R.id.img_head_portrait:
            case R.id.tv_nickname:
            case R.id.tv_signature:
                fragmentManager.beginTransaction().replace(R.id.layout_main, new UserInfoFragment())
                        .addToBackStack(null)
                        .commit();
                break;
            case R.id.tv_attention:
                break;
            case R.id.tv_fans:
                break;
            case R.id.img_qrcode:
                fragmentManager.beginTransaction().replace(R.id.layout_main, new QRCodeFragment())
                        .addToBackStack(null)
                        .commit();
                break;
            case R.id.layout_sold:
                break;
            case R.id.layout_buy:
                break;
            case R.id.layout_collected:
                break;
        }
    }

}
